package com.zhuozhou.jdyc.util.media;

import android.app.Activity;
import android.content.Context;

import androidx.fragment.app.Fragment;

import com.zhuozhou.jdyc.base.BaseView;
import com.zhuozhou.jdyc.util.permission.PermissionsChecker;

/**
 * Created by fz on 2021/2/7 9:10
 * describe:mediaUtil配置类
 */
public class MediaBuilder {
    /**
     * 设置视频拍摄时长，单位：秒
     */
    public int maxVideoTime = 30;
    /**
     * 视频压缩质量
     */
    private int videoQuality = MediaHelper.VIDEO_LOW;
    /**
     * 最大相册选择数量
     */
    public int imageAlbumCount = MediaHelper.ALBUM_MAX_COUNT;
    /**
     * 图片压缩大小限制，默认200
     */
    public int imageQualityCompress = 200;
    private BaseView baseView;
    private Activity mActivity;
    private Fragment mFragment;
    private final Context mContext;
    private PermissionsChecker mPermissionsChecker;

    private String imageOutPutPath;
    private String videoOutPutPath;

    public MediaBuilder(Activity mActivity, BaseView baseView) {
        this.mActivity = mActivity;
        this.baseView = baseView;
        this.mContext = mActivity;
        imageOutPutPath = mContext.getExternalFilesDir("image").getAbsolutePath();
        videoOutPutPath = mContext.getExternalFilesDir("video").getAbsolutePath();
    }

    public MediaBuilder(Fragment mFragment, BaseView baseView) {
        this.mFragment = mFragment;
        this.baseView = baseView;
        this.mContext = mFragment.getContext();
        imageOutPutPath = mContext.getExternalFilesDir("image").getAbsolutePath();
        videoOutPutPath = mContext.getExternalFilesDir("video").getAbsolutePath();
    }

    public String getImageOutPutPath() {
        return imageOutPutPath;
    }

    public void setImageOutPutPath(String imageOutPutPath) {
        this.imageOutPutPath = imageOutPutPath;
    }

    public String getVideoOutPutPath() {
        return videoOutPutPath;
    }

    public void setVideoOutPutPath(String videoOutPutPath) {
        this.videoOutPutPath = videoOutPutPath;
    }

    public MediaBuilder setBaseView(BaseView baseView) {
        this.baseView = baseView;
        return this;
    }

    public MediaBuilder setImageQualityCompress(int imageQualityCompress) {
        this.imageQualityCompress = imageQualityCompress;
        return this;
    }

    public MediaBuilder setImageAlbumCount(int imageAlbumCount) {
        this.imageAlbumCount = imageAlbumCount;
        return this;
    }

    public Context getContext() {
        return mContext;
    }

    public MediaBuilder setMaxVideoTime(int maxVideoTime) {
        this.maxVideoTime = maxVideoTime;
        return this;
    }

    public MediaBuilder setVideoQuality(int videoQuality) {
        this.videoQuality = videoQuality;
        return this;
    }

    public int getMaxVideoTime() {
        return maxVideoTime;
    }

    public int getVideoQuality() {
        return videoQuality;
    }

    public int getImageAlbumCount() {
        return imageAlbumCount;
    }

    public int getImageQualityCompress() {
        return imageQualityCompress;
    }

    public BaseView getBaseView() {
        return baseView;
    }

    public Activity getActivity() {
        return mActivity;
    }

    public Fragment getFragment() {
        return mFragment;
    }

    public MediaHelper builder() {
        return new MediaHelper(this);
    }

    public PermissionsChecker getPermissionsChecker() {
        if (mPermissionsChecker == null) {
            mPermissionsChecker = new PermissionsChecker(mContext);
        }
        return mPermissionsChecker;
    }

    public void setPermissionsChecker(PermissionsChecker mPermissionsChecker) {
        this.mPermissionsChecker = mPermissionsChecker;
    }
}
